<?php
/**
 * ShopEx licence
 *
 * @copyright  Copyright (c) 2005-2010 ShopEx Technologies Inc. (http://www.shopex.cn)
 * @license  http://ecos.shopex.cn/ ShopEx License
 */

/**
 * 供应商页面布局 edit by kim
 * @auther 
 * @version 0.1
 * @package b2c_lib_finder
 */
class b2c_finder_operator_member{
    var $detail_basic;
    var $detail_main;
    var $column_edit;
    public function __construct($app)
    {
        $this->app = $app;

		$this->detail_basic = app::get('b2c')->_('集货员基础信息');
        $this->detail_edit = app::get('b2c')->_('编辑会员');
        $this->column_edit = app::get('b2c')->_('操作');
    }
    function detail_basic($id){
        $render = app::get('b2c')->render();
        $oitem = kernel::single("b2c_mdl_operator_member");
        $items = $oitem->getList('*',array('id' => $id), 0, 1);
        $render->pagedata['data'] = $items[0];
        return $render->fetch('admin/operator/basicmsg.html');
    }

    function  detail_edit($id = null){
		$oitem = kernel::single("b2c_mdl_operator_member");
		$members = $oitem->getRow('member_id',array('id'=>$id));
		$member_id = $members['member_id'];

        $app = app::get('b2c');
        $member_model = $app->model('members');
        $userPassport = kernel::single('b2c_user_passport');
        $userObject = kernel::single('b2c_user_object');

        if($_POST){
            $saveData['b2c_members'] = $_POST;
            unset($saveData['b2c_members']['pam_members']);
            #↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓记录管理员操作日志@lujy↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
            if($obj_operatorlogs = kernel::service('operatorlog.members')){
                $olddata = app::get('b2c')->model('members')->dump($member_id);
            }
            #↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑记录管理员操作日志@lujy↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
            if( $member_model->save($saveData['b2c_members']) ){
                #↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓记录管理员操作日志@lujy↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
                if($obj_operatorlogs = kernel::service('operatorlog.members')){
                    if(method_exists($obj_operatorlogs,'detail_edit_log')){
                        $newdata = app::get('b2c')->model('members')->dump($member_id);
                        $obj_operatorlogs->detail_edit_log($newdata['contact'],$olddata['contact']);
                    }
                }
                #↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑记录管理员操作日志@lujy↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
                if( $member_rpc_object = kernel::service("b2c_member_rpc_sync") ) {
                    $member_rpc_object->modifyActive($member_id);
                }
                $msg = app::get('b2c')->_('保存成功');
                header('Content-Type:text/jcmd; charset=utf-8');
                echo '{success:"'.$msg.'",_:null}';
                exit;
            }else{
                $msg = app::get('b2c')->_('保存失败');
                header('Content-Type:text/jcmd; charset=utf-8');
                echo '{error:"'.$msg.'",_:null}';
                exit;
            }
        }

        $membersData = $userObject->get_members_data(array('account'=>'*','members'=>'*'),$member_id,false);
        $member_lv=$app->model("member_lv");
        foreach($member_lv->getMLevel() as $row){
            $options[$row['member_lv_id']] = $row['name'];
        }
        $membersData['lv']['options'] = is_array($options) ? $options : array(app::get('b2c')->_('请添加会员等级')) ;
        $membersData['lv']['value'] = $membersData['members']['member_lv_id'];

        $render = $app->render();
        $render->pagedata['mem'] = $membersData;
        $render->pagedata['attr'] = $userPassport->get_signup_attr($member_id);
        $render->pagedata['member_id'] = $member_id;
        return $render->fetch('admin/member/edit.html');
    }

    public function column_edit($row){
        $render = $this->app->render();
        $arr = array(
            'app'=>$_GET['app'],
            'ctl'=>$_GET['ctl'],
            'act'=>$_GET['act'],
            'finder_id'=>$_GET['_finder']['finder_id'],
            'action'=>'detail',
            'finder_name'=>$_GET['_finder']['finder_id'],
        );
        $arr_link = array(
            'info'=>array(
                'detail_basic'=>array(
                    'href'=>'javascript:void(0);',
                    'submit'=>'index.php?'.utils::http_build_query($arr).'&finderview=detail_basic&id='.$row['id'].'&_finder[finder_id]='.$_GET['_finder']['finder_id'],'label'=>app::get('b2c')->_('集货员基础信息'),
                    'target'=>'tab',
                ),
            ),
            'finder'=>array(
                'detail_main'=>array(
					'href'=>'javascript:void(0);',
                    'submit'=>'index.php?'.utils::http_build_query($arr).'&finderview=detail_edit&id='.$row['id'].'&_finder[finder_id]='.$_GET['_finder']['finder_id'],'label'=>app::get('b2c')->_('编辑会员'),
                    'target'=>'tab',
                ),
            ),
            'mine'=>array(
                'edit_msg'=>array(
                    'href'=>'index.php?app=b2c&ctl=admin_operator_member&act=edit&bid='.$row['id'].'&finder_id='.$_GET['_finder']['finder_id'],
                    'label'=>app::get('b2c')->_('修改基础信息'),
                    'target'=>'blank',
                ),
            ),
        );
        $render->pagedata['arr_link'] = $arr_link;
        $render->pagedata['handle_title'] = app::get('b2c')->_('编辑');
        $render->pagedata['is_active'] = 'true';
        return $render->fetch('admin/actions.html');
    }
}
